package com.taocyb.web.uc.seller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.taocyb.commons.uc.entity.Seller;
import com.taocyb.commons.uc.entity.User;
import com.taocyb.commons.uc.service.SellerService;
import com.taocyb.commons.uc.vo.SellerVo;
import com.taocyb.constant.EnableStatus;
import com.taocyb.constant.ShopType;
import com.taocyb.framework.orm.Page;
import com.taocyb.framework.security.simple.Authentication;
import com.taocyb.web.BaseLoginController;

/**
 * 我的卖家
 */
@Controller
@RequestMapping(value = "/uc/seller")
public class SellerController extends BaseLoginController{
	
	@Autowired
	private SellerService sellerService;
	
	/**
	 * 首页 
	 */
	@Authentication
	@RequestMapping(value = "")
	public String index(HttpServletRequest request, Model model){
		return this.taobao(request, model);
	}
	
	/**
	 * 淘宝卖家首页 
	 */
	@Authentication
	@RequestMapping(value = "taobao")
	public String taobao(HttpServletRequest request, Model model){
		User user = super.getLoginUser(request);
		
		SellerVo vo = new SellerVo();
		vo.setUserId(user.getId());
		vo.setShopType(ShopType.TAOBAO.key);
		
		Page<Seller> page = new Page<Seller>();
		
		page = sellerService.findSellerList(vo, page);
		
		model.addAttribute("page", page);
		return "uc/seller/taobao-index";
	}
	
	/**
	 * 拍拍卖家首页 
	 */
	@Authentication
	@RequestMapping(value = "paipai")
	public String paipai(HttpServletRequest request, Model model){
		return "uc/seller/paipai-index";
	}
	
	/**
	 * 新增数据
	 */
	@Authentication
	@RequestMapping(value = "save")
	public String save(String sellerName, HttpServletRequest request){
		User user = super.getLoginUser(request);
		
		Seller seller = new Seller();
		seller.setUserId(user.getId());
		seller.setLoginName(user.getLoginName());
		seller.setSellerName(sellerName);
		seller.setShopType(ShopType.TAOBAO.key);
		seller.setStatus(EnableStatus.YES.key);
		seller.setLevel(0); 
		sellerService.saveSeller(seller);
		
		return null;
	}
}
